package com.gitee.feizns.quickstart.ding.talk.event.contacts;

import com.dingtalk.open.app.api.GenericEventListener;
import com.dingtalk.open.app.api.message.GenericOpenDingTalkEvent;
import com.dingtalk.open.app.stream.protocol.event.EventAckStatus;
import lombok.RequiredArgsConstructor;

import java.util.List;
import java.util.function.Consumer;

/**
 * 组织部门新增事件
 * @author feizns
 * @since 2025/3/24
 */
@RequiredArgsConstructor
public class OrgDeptRemoveListener implements GenericEventListener {

    /**
     * 处理
     */
    private final Consumer<Long> handler;

    @Override
    public EventAckStatus onEvent(GenericOpenDingTalkEvent event) {
        return onEvent(event, handler);
    }

    /**
     * 活动
     * @param event 事件
     * @param handler 处理器
     * @return {@link EventAckStatus }
     */
    public static EventAckStatus onEvent(GenericOpenDingTalkEvent event, Consumer<Long> handler) {
        if ( "org_dept_remove".equals(event.getEventType()) ) {
            List<Long> deptId = event.getData().getList("deptId", Long.class);
            if ( handler != null )
                deptId.forEach(handler);
        }
        return EventAckStatus.SUCCESS;
    }

}
